import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Microsoft
 * Date: 2022-12-17
 * Time: 11:02
 */
public class Test {
    public static int binarySearch(int[] arr , int key) {
        int left = 0;
        int right = arr.length - 1;
        while(left <= right) {
            int mid = (left + right) / 2;
            if (arr[mid] < key) {
                left = mid + 1;
            }
            if (arr[mid] > key) {
                right = mid - 1;
            }
            if (arr[mid] == key) {
                return mid;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6 , 7};
        System.out.println(binarySearch(arr, 9));
        System.out.println(Arrays.binarySearch(arr,9));
        System.out.println(Arrays.toString(arr));
    }
}



//    //奇数放左边，偶数放右边
//    public static void func(int[] array) {
//        int left = 0;
//        int right = array.length - 1;
//        while(left < right) {
//            while (left < right && array[left] % 2 == 1) {
//                left++;
//            }
//            while (left < right && array[right] % 2 == 0) {
//                right--;
//            }
//            int tmp = array[left];
//            array[left] = array[right];
//            array[right] = tmp;
//        }
//    }